<?php
/**
 * Main executable file
 * Run core of the application
 * 
 * @version 0.1
 * @author Sergey Tihonov
 */

/**
 * Determination root directory
 *
 * @return string
 */
function get_root_dir()
{
    if (empty($_SERVER['DOCUMENT_ROOT'])) {
        $_SERVER['DOCUMENT_ROOT'] = dirname($_SERVER['SCRIPT_FILENAME']);
    }
    
    return rtrim($_SERVER['DOCUMENT_ROOT'], '/\\');
}

/**
 * Initialization constanst
 */
 
// Path for root dir
define('DOCUMENT_ROOT', get_root_dir());
 
// Path for engine dir
define('ENGINE_DIR', DOCUMENT_ROOT . '/engine');
 
// Path for application dir
define('APPLICATION_DIR', DOCUMENT_ROOT . '/application');

/**
 * Initialization application
 */
require APPLICATION_DIR . '/boot.php';
$app = new \Application\Boot();

/**
 * Initialization routes
 * 
 * Set variable type necessary!
 */
$app->get('/', 'ads.main');
$app->get('/auto/:marka/:model/:id', 'ads.main', array(
    'marka' => '(\w+)',
    'model' => '(\w+)',
    'id' => '(\d+)',
));
$app->get('/hello_:id/:question', 'ads.main', array('id' => '(\d+)', 'question' => '(\w+)'));

/**
 * Run application 
 */
$app->run();        